<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.*" %>
<%@ page import="com.niit.Student" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JSTL例子</title>
</head>
<body>
<h1>1.set 标签：</h1>
<!-- 方式一 -->
<c:set var="username" value="zhangsan" scope="page"></c:set>
username变量的值：${username}<br>
<!-- 方式二 -->
<c:set var="email" scope="page">12345@qq.com</c:set>
email变量的值：${email}<br>

<jsp:useBean id="student" class="com.niit.Student" scope="application"/>
<jsp:setProperty name="student" property="id" value="2023001" />
<jsp:setProperty name="student" property="name" value="xiaohong" />
<jsp:setProperty name="student" property="age" value="20" />

<!-- 将javaBean(即student对象)的name属性的值赋值给变量myName -->
<c:set var="myName" target="${student}" value="${student.name}"></c:set>
myName变量的值：${myName}<br>
<!-- c:out用于输出 -->
<c:out value="${myName}"></c:out><br>

原始:student对象的name属性的值：${student.name}<br>
<!-- 将javaBean(即student对象)的name属性的值更新为zhangsan -->
<c:set target="${student}" property="name" value="zhangsan"></c:set>
更新后：student对象的name属性的值：${student.name}<br>

<h1>2.if 标签：</h1>
<c:set var="age" value="20"></c:set>
<c:if test="${age>=18}">
<div style="font-size:30px;color:blue">成年人</div>
</c:if>
<c:if test="${age<18}">
<div style="font-size:30px;color:red">未成年人</div>
</c:if>
<br>
<c:set var="num1">5</c:set>
<c:set var="num2">6</c:set>
<c:if test="${ num1>num2 }" var="result"></c:if>
num1>num2比较的结果：${result}


<h1>3.forEach 标签</h1>
<!-- 
	begin:开始的下标
	end:结束的下标
	var:接受值的变量
	step:增幅（步进值）
 -->
<c:forEach begin="1" end="10" var="i" step="2">
	<div style="font-size:24px;color:blue">${i}</div>
</c:forEach>

<!-- 模拟表格的展示 -->
<!-- 模拟数据 -->
<%
	List<Student> lstStudents = new ArrayList<>();
	lstStudents.add(new Student("1","zhangsan","20"));
	lstStudents.add(new Student("2","lis","24"));
	lstStudents.add(new Student("3","wangwu","23"));
	lstStudents.add(new Student("4","zhaoliu","21"));
	// 把数据放到页面中
	pageContext.setAttribute("lstStudents", lstStudents);
%>


<table border="1">
	<tr>
		<th>序号</th>
		<th>姓名</th>
		<th>年龄</th>
	</tr>	
	<c:forEach items="${lstStudents}" var="stu">
		<tr>
			<td>${stu.id}</td>
			<td>${stu.name}</td>
			<td>${stu.age}</td>
		</tr>
	</c:forEach>
	<!-- <tr>
		<td>1</td>
		<td>zhangsan</td>
		<td>20</td>
	</tr>
	<tr>
		<td>2</td>
		<td>zhangsan</td>
		<td>20</td>
	</tr>
	<tr>
		<td>3</td>
		<td>zhangsan</td>
		<td>20</td>
	</tr>
 -->	
</table>








</body>
</html>
